package com.sc.smartcommunity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.smartcommunity.domain.OwnerComplaint;
import com.sc.smartcommunity.mapper.OwnerComplaintMapper;
import com.sc.smartcommunity.service.OwnerComplaintService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OwnerComplaintServiceImpl extends ServiceImpl<OwnerComplaintMapper, OwnerComplaint> implements OwnerComplaintService {

    @Override
    public boolean saveComplaint(OwnerComplaint complaint) {
        complaint.setCreateTime(LocalDateTime.now());
        complaint.setUpdateTime(LocalDateTime.now());
        return save(complaint);
    }

    @Override
    public List<OwnerComplaint> getComplaintsByOwnerphone(String phoneNumber) {

        LambdaQueryWrapper<OwnerComplaint> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OwnerComplaint::getPhoneNumber, phoneNumber)
                .orderByDesc(OwnerComplaint::getCreateTime); // 按创建时间倒序

        return baseMapper.selectList(queryWrapper);
    }
}